

package top.continew.admin.question.mapper.question;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.continew.admin.question.model.question.UserDoQuestion;
import top.continew.starter.data.mp.base.BaseMapper;

public interface UserDoQuestionMapper extends BaseMapper<UserDoQuestion> {
    @Select("""

                    SELECT count(DISTINCT DATE(a.create_time))
        from
        user_do_question a LEFT JOIN  question b on a.question_id=b.id
        WHERE
        b.specification_type=#{specificationType}
        and a.user_id=#{userId}

        """)
    Long getDoQuestionDay(@Param("userId") Long userId, @Param("specificationType") Long specificationType);

    @Select("""
        SELECT count(*)
        FROM  user_do_question a LEFT JOIN  question b on a.question_id=b.id
        WHERE a.user_id=#{userId} AND DATE(a.create_time) = CURRENT_DATE
        and  b.specification_type=#{specificationType}
        """)
    Long getQuestionTodayDoSum(@Param("userId") Long userId, @Param("specificationType") Long specificationType);

    @Select("""
        SELECT count(*)
        FROM user_do_question a LEFT JOIN  question b on a.question_id=b.id
        WHERE a.user_id=#{userId}
        and  b.specification_type=#{specificationType}
        AND DATE(a.create_time)
        = (SELECT MAX(DATE(create_time)) FROM user_do_question WHERE user_id=#{userId} AND DATE(create_time) < CURRENT_DATE)
        """)
    Long getQuestionLastTimeDoSum(@Param("userId") Long userId, @Param("specificationType") Long specificationType);
}
